package com.lingyuan.discounts.factory;

import com.lingyuan.discounts.tactics.DiscountStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

/**
 * @ClassName：DiscoutStrategyFactory
 * @Author: LeiHao
 * @Date: 2024/10/3 10:58
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Service
public class DiscountStrategyFactory {
    private ApplicationContext context;

    @Autowired
    public DiscountStrategyFactory(ApplicationContext context) {
        this.context = context;
    }

    public DiscountStrategy getStrategy(String strategyName) {
        return context.getBean(strategyName, DiscountStrategy.class);
    }
}
